package com.ftg.learn.springbootmq.work.controller;

import com.ftg.learn.springbootmq.work.Producer.MessageProducer;
import com.ftg.learn.springbootmq.work.entity.StudentEntity;
import com.ftg.learn.util.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * 学生控制器
 *
 * @author 布衣
 */
@RestController
@RequestMapping("/student")
@Tag(name = "学生管理接口", description = "学生增删改查相关接口")
public class StudentController {

    @Resource
    private MessageProducer messageProducer;


    @PostMapping("/add")
    @Operation(summary = "添加学生", description = "添加一个新的学生信息")
    public R<Boolean> add(@RequestBody StudentEntity stu){
        messageProducer.sendStructuredMessage(stu,"add");
        return R.ok(true);
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除学生", description = "根据ID删除学生信息")
    public R<Boolean> delete(@RequestParam("id")String id){
        messageProducer.sendStringMessage(id,"delete");
        return R.ok(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新学生信息", description = "更新学生信息")
    public R<Boolean> update(@RequestBody StudentEntity stu){
        messageProducer.sendStructuredMessage(stu,"update");
        return R.ok(true);
    }

}
